package com.shanzhu.parking.controller;


import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.shanzhu.parking.common.R;
import com.shanzhu.parking.entity.po.Fee;
import com.shanzhu.parking.entity.po.FeeSetting;
import com.shanzhu.parking.entity.po.User;
import com.shanzhu.parking.entity.vo.MsgVo;
import com.shanzhu.parking.service.FeeService;
import com.shanzhu.parking.service.FeeSettingService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 车位费用 控制层
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/fee")
public class FeeController {

    private final FeeService feeService;
    private final FeeSettingService feeSettingService;

    /**
     * 查询车位类型收费信息
     * 
     * 为了兼容旧代码，该接口代理调用/fee-setting/list接口
     *
     * @param carType 车位类型
     * @return 缴费记录
     */
    @GetMapping("/list")
    public R<List<FeeSetting>> listFee(String carType) {
        // 从FeeSettingService获取数据，以保持与新接口的一致性
        return R.success(feeSettingService.list(
            Wrappers.<FeeSetting>lambdaQuery()
                .like(carType != null && !carType.isEmpty(), FeeSetting::getCarType, carType)
                .orderByAsc(FeeSetting::getCarType)
                .orderByAsc(FeeSetting::getStartTime)
        ));
    }

    /**
     * 更新车位收费费用
     *
     * @param fee 车位信息
     * @return 结果
     */
    @PostMapping("update")
    public R<MsgVo> updateFee(@RequestBody Fee fee) {
        return R.success(feeService.updateFee(fee));
    }


    /**
     * 用户余额充值
     *
     * @param user 用户信息
     * @return 结果
     */
    @PostMapping("/userFee")
    public R<Object> feeUser(@RequestBody User user) {
        return R.success(feeService.addUserFee(user));
    }

}

